package flc.ast.adapter;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.ResumeBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class SkillAdapter extends StkProviderMultiAdapter<ResumeBean.DetailItem> {

    public SkillAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new SkillProvider());
    }

    private boolean isEdit = true;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class SkillProvider extends BaseItemProvider<ResumeBean.DetailItem> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_skill;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, ResumeBean.DetailItem bean) {
            if (TextUtils.isEmpty(bean.getText())) {
                baseViewHolder.getView(R.id.llSkillItem).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivSkillItemAdd).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.llSkillItem).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivSkillItemAdd).setVisibility(View.GONE);
                baseViewHolder.setText(R.id.tvSkillItemName, bean.getText());
                if (isEdit){
                    baseViewHolder.getView(R.id.ivSkillItemDelete).setVisibility(View.VISIBLE);
                }else {
                    baseViewHolder.getView(R.id.ivSkillItemDelete).setVisibility(View.GONE);
                }
            }
        }
    }

}
